
rm(list=ls())
library(ctgt)
library(stringr)
library(xlsx)

load("gmincmax3.Rdata")
level = tc3$level
tmin= tc3$tmin
crt=tc3$crt
cmax = tc3$cmax
levs = tc3$levs
namebank = c("3", "13", "23", "34", "35","123", "134", "135", "234", "235", "345", "1234", "1235", "1345", "2345", "12345")
h3da_1 = as.data.frame(cbind(level,tmin,crt),col.names = c("level","tmin","crt"))
h3da_2 = as.data.frame( cbind(levs,cmax),col.names = c("levs","cmax"))
line_types <- c("l1" =1,"l2" =3,"l3" =5)
point_types <- c("p3"=16,"p4" = 17,"p5"=15)

load("cross3.Rdata")
cda = as.data.frame(cross3)
cda_p = as.data.frame(cbind(x=cda$lres[-c(1,length(cda$lres))],y=cda$cres[-c(1,2)]))
library(ggplot2)
library(ggrepel)

#jpeg("cp3.jpg",width = 16, height = 12, units = 'cm', res = 600)

cp3 = ggplot(h3da_1, aes(level, tmin)) + theme_classic() + xlim(level[1], level[16]+1) + ylim(0,tmin[16]+30 ) + 
  labs(y=expression(g[min]~and~c[max]), x="level") +
  #theme(plot.title = element_text(hjust = 0.5, face="bold",size=16))+
  #geom_text(aes(level, tmin),data = h3da_1[c(1,4,11,15,16),],label=namebank[c(1,4,11,15,16)],vjust = -0.5, nudge_y = 9,size= 3) +
  geom_line(aes(levs, cmax,linetype="l2"),data = h3da_2) + 
  geom_line(aes(level, tmin,linetype= "l1"), data = h3da_1[c(1,4,11,15,16),]) +
  #geom_point(aes(level, tmin,shape = "p3"), data = h3da_1[c(1,4,11,15,16),]) +
  geom_step(data=cda, mapping=aes(x=lres, y=cres,linetype="l3"))+
  geom_point(aes(x, y,shape="p5"),data=cda_p)+
  #geom_point(aes(level, crt,shape = "p4"), data = h3da_1[c(1,4,11,15,16),]) +
  scale_shape_manual(values=c(15), labels = c(expression(c[max])), name="point") +
  scale_linetype_manual(values=c(1,3,5), labels = c(expression(g[min]), expression(c[max]), "Algorithm"), name="line")+
  theme(legend.position = "none") +
  ggtitle(expression(H[3]) )+
  theme(plot.title = element_text(hjust=0.5))

#dev.off()

load("gmincmax2.Rdata")
level = tc2$level
tmin= tc2$tmin
crt=tc2$crt
cmax = tc2$cmax
levs = tc2$levs
namebank = c("2", "12", "23", "24", "25","123", "124", "125", "234", "235", "245", "1234", "1235", "1245", "2345", "12345")
h3da_1 = as.data.frame(cbind(level,tmin,crt),col.names = c("level","tmin","crt"))
h3da_2 = as.data.frame( cbind(levs,cmax),col.names = c("levs","cmax"))
line_types <- c("l1" =1,"l2" =3,"l3" =5)
point_types <- c("p3"=16,"p4" = 17,"p5"=15)

load("cross2.Rdata")
cda = as.data.frame(cross2)
cda_p = as.data.frame(cbind(x=cda$lres[-c(1,length(cda$lres))],y=cda$cres[-c(1,2)]))
library(ggplot2)

#jpeg("cp2.jpg",width = 16, height = 12, units = 'cm', res = 600)

cp2 = ggplot(h3da_1, aes(level, tmin)) + theme_classic() + xlim(level[1], level[16]+1) + ylim(0,tmin[16]+30 ) + 
  labs(y=expression(g[min]~and~c[max]), x="level") + 
  #theme(plot.title = element_text(hjust = 0.5, face="bold",size=16))+
  #geom_text(aes(level, tmin),data = h3da_1[c(1,4,11,14,16),],label=namebank[c(1,4,11,14,16)],vjust = -0.5, nudge_y = 9,size= 3) +
  geom_line(aes(levs, cmax,linetype="l2"),data = h3da_2) + 
  geom_line(aes(level, tmin,linetype= "l1"), data = h3da_1[c(1,4,11,14,16),]) +
  #geom_point(aes(level, tmin,shape = "p3"), data = h3da_1[c(1,4,11,14,16),]) +
  geom_step(data=cda, mapping=aes(x=lres, y=cres,linetype="l3"))+
  geom_point(aes(x, y,shape="p5"),data=cda_p)+
  #geom_point(aes(level, crt,shape = "p4"), data = h3da_1[c(1,4,11,15,16),]) +
  scale_shape_manual(values=c(15), labels = c(expression(c[max])), name="point") +
  scale_linetype_manual(values=c(1,3,5), labels = c(expression(g[min]), expression(c[max]), "Algorithm"), name="line") + 
  theme(legend.position = "none")+
  ggtitle(expression(H[2]) )+
  theme(plot.title = element_text(hjust=0.5))

#dev.off()


library(ggpubr)
jpeg("cp.jpg",width = 16, height = 20, units = 'cm', res = 600)
ggarrange(cp3,cp2, ncol = 1, nrow = 2,legend = "bottom", common.legend = TRUE)
dev.off()


# load("gmincmax1.Rdata")
# level = tc1$level
# tmin= tc1$tmin
# crt=tc1$crt
# cmax = tc1$cmax
# levs = tc1$levs
# namebank = c("1", "12", "13", "14", "15","123", "124", "125", "134", "135", "145", "1234", "1235", "1245", "1345", "12345")
# h3da_1 = as.data.frame(cbind(level,tmin,crt),col.names = c("level","tmin","crt"))
# h3da_2 = as.data.frame( cbind(levs,cmax),col.names = c("levs","cmax"))
# line_types <- c("l1" =1,"l2" =3,"l3" =5)
# point_types <- c("p3"=16,"p4" = 17, "p5"=15)
# 
# load("cross1.Rdata")
# cda = as.data.frame(cross1)
# cda_p = as.data.frame(cbind(x=cda$lres[-c(1,length(cda$lres))],y=cda$cres[-c(1,2)]))
# library(ggplot2)
# 
# jpeg("cp1.jpg",width = 16, height = 12, units = 'cm', res = 600)
# 
# ggplot(h3da_1, aes(level, tmin)) + theme_classic() + xlim(level[1], level[16]+1) + ylim(0,tmin[16]+30 ) + 
#   labs(y=expression(g[min]~and~c[max]), x="level") +
#   #theme(plot.title = element_text(hjust = 0.5, face="bold",size=16))+
#   #geom_text(aes(level, tmin),data = h3da_1[c(1,4,11,14,16),],label=namebank[c(1,4,11,14,16)],vjust = -0.5, nudge_y = 9,size= 3) +
#   geom_line(aes(levs, cmax,linetype="l2"),data = h3da_2) + 
#   geom_line(aes(level, tmin,linetype= "l1"), data = h3da_1[c(1,4,11,14,16),]) +
#   #geom_point(aes(level, tmin,shape = "p3"), data = h3da_1[c(1,4,11,14,16),]) +
#   #geom_point(aes(level, crt,shape = "p4"), data = h3da_1[c(1,4,11,14,16),]) +
#   geom_step(data=cda, mapping=aes(x=lres, y=cres,linetype="l3"))+
#   geom_point(aes(x, y,shape="p5"),data=cda_p)+
#   #geom_point(aes(level, crt,shape = "p4"), data = h3da_1[c(1,4,11,15,16),]) +
#   scale_shape_manual(values=c(15), labels = c( expression(c[max])), name="point") +
#   scale_linetype_manual(values=c(1,3,5), labels = c(expression(g[min]), expression(c[max]), "Algorithm"), name="line") 
# 
# dev.off()
# 
# 
